package vue.panneau1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PopupChoixLibelleContrainte extends JPanel implements ActionListener
{
	private static final long serialVersionUID = 1L;
	private Interface2DZone1 zone2D;
	private Interface3DZone1 zone3D;
	private JDialog fen;
	private JLabel label;
	private JTextField jtfLib;
	private JButton bvalider;
	private int index;
	private boolean is3D;

	public PopupChoixLibelleContrainte(Object interfaceZone1,int index,boolean is3D)
	{
		String libelle = "";
		if(is3D)
		{
			this.zone3D = (Interface3DZone1)interfaceZone1;
			libelle = zone3D.getTableModelEquation().getEquation3DAt(index).getLibelle();
		}
		else
		{
			this.zone2D = (Interface2DZone1)interfaceZone1;
			libelle = zone2D.getTableModelEquation().getEquation2DAt(index).getLibelle();
		}
		this.index = index;
		this.is3D = is3D;
		
		label = new JLabel(" Contrainte n° " + (index+1) + " :");

		jtfLib = new JTextField(12);		
		jtfLib.setText(libelle);
		
		bvalider = new JButton("Valider");
		bvalider.addActionListener(this);
		
		this.setLayout(new GridLayout(0,2));
		add(label);
		add(jtfLib);
		add(new JLabel(""));
		add(bvalider);		
		
		fen = new JDialog();
		fen.add(this);
		fen.setTitle("Ajout du libellé");
		if(is3D)
		{
			fen.setLocationRelativeTo(zone3D);
		}
		else
		{
			fen.setLocationRelativeTo(zone2D);
		}
		fen.setResizable(false);
		fen.setAlwaysOnTop(true);
		fen.pack();
		fen.setVisible(true);
	}

	public void actionPerformed(ActionEvent e) 
	{	
		if(is3D)
		{
			zone3D.choisirLibelleContrainte(index,jtfLib.getText());
		}
		else
		{
			zone2D.choisirLibelleContrainte(index,jtfLib.getText());
		}
		fen.dispose();
	}
}


